﻿//----------------------------------------------------------------
// <copyright file="ITeamFoundationFacade.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//----------------------------------------------------------------

using System.Collections.Generic;

namespace MptCodeLibrary.TeamFoundation
{
    public interface ITeamFoundationFacade
    {
        /// <summary>
        /// Subscribes to the WorkItemChangedEvent for the defined TFS server
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="receiverPath">Where the TFS event will be delivered to.</param>
        /// <param name="filterExpression">The filter expression, if any, to use for the event.  
        /// An example would be filtering by team project.</param>
        void SignupForReceivingEvent(string serverName, string receiverPath, string filterExpression);

        /// <summary>
        /// This method will look at the work item types for the projects and find the four WIT Categories 
        /// {Value Prop, Feature group, feature, deliverable} that the code wants to receive change events for.
        /// </summary>
        /// <param name="serverNames">The TFS server names the events will be on.</param>
        /// <param name="projectNames">The project names the events care about.</param>
        /// <returns>Collection of unique Work Item Type names that will map to WIT categories</returns>
        IEnumerable<string> GetEventWorkItemTypesForProjects(IEnumerable<string> serverNames, IEnumerable<string> projectNames);

        /// <summary>
        /// Gets the global lists from the server as a XDocument.
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        string GetGlobalLists(string serverName);

        /// <summary>
        /// Adds the global list to the specified tfs server
        /// </summary>
        /// <param name="serverName">Name fo the TFS Server to add the list to.</param>
        /// <param name="updatedGlobalList">The XML string of the updated global list.</param>
        void SetGlobalList(string serverName, string updatedGlobalList);

        /// <summary>
        /// Gets the WIT for project for the type specified.
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="workItemType">WIT.</param>
        /// <returns>Xml string that represents the WIT</returns>
        string GetWorkItemTypeForProject(string serverName, string projectName, string workItemType);

        /// <summary>
        /// Updates the WIT for project
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="workItemTypeXml">The full XML of the work item type to update</param>
        void UpdateWorkItemTypeForProject(string serverName, string projectName, string workItemTypeXml);

        /// <summary>
        /// Updates the existing work items for the project that have the ParentShortName field set to existingParentShortName 
        /// with newParentShortName
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="projectName">Name of the Team Project.</param>
        /// <param name="existingParentShortName">The exisitng parent short name.</param>
        /// <param name="newParentShortName">The new shart name of the parent.</param>
        void UpdateExistingWorkItemsWithNewParent(string serverName, string projectName,
                                                  string existingParentShortName, string newParentShortName);

        /// <summary>
        /// Gets the work item based on the System.Id.
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="workItemId">The work item id.</param>
        WorkItemSummary GetWorkItem(string serverName, int workItemId);

        /// <summary>
        /// Retrieves the work items that have changed on the tfs server for the projects in the last 48 hours
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="projectsToCheck">The projects that are being monitored on the TFS server.  An empty string means all projects on the server</param>
        /// <returns>Collection of work items that have changed in the last 48 hours</returns>
        IEnumerable<WorkItemSummary> ChangedWorkItems(string serverName, IEnumerable<string> projectsToCheck);

        /// <summary>
        /// Gets the work items for the project of the type specified.
        /// </summary>
        /// <param name="serverName">Name of the TFS server.</param>
        /// <param name="projectName">Name of the project to get the work items for.</param>
        /// <param name="workItemType">Type of the work items to retrieve.</param>
        /// <returns>Collection of work items for the provided type</returns>
        IEnumerable<WorkItemSummary> GetWorkItemsForProjectOfType(string serverName, string projectName,
                                                                  string workItemType);

        /// <summary>
        /// Returns true if the project is in the work item store for the server.
        /// </summary>
        bool ProjectExists(string serverName, string teamProjectName);
    }
}